package definite.Guide.Book.Chap01_02;

import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;

public class FocusSample {

	public static void main(String[] args) {
		Runnable runner = new Runnable() {

			@Override
			public void run() {
				JFrame frame = new JFrame();
				frame.setTitle("Focus Sample");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				ActionListener actionListener = new ActionFocusMover();
				MouseListener mouseListener = new MouseFocusMover();
				frame.setLayout(new GridLayout(3, 3));
				for (int i = 0; i < 10; i++) {
					JButton button = new JButton(Integer.toString(i));
					button.addActionListener(actionListener);
					button.addMouseListener(mouseListener);
					if (i % 2 == 0)
						button.setFocusable(false);

					frame.add(button);
				}

				frame.setSize(300, 200);
				frame.setVisible(true);
			}
		}; // end runnable

		EventQueue.invokeLater(runner);
	}

}
